package com.stx.blog.service.impl;


import java.util.ArrayList;
import java.util.List;

import com.stx.blog.dao.UserDao;
import com.stx.blog.exception.BlogException;
import com.stx.blog.service.UserService;
import com.stx.blog.vo.FriendVo;
import com.stx.blog.vo.UserVo;

public class UserServiceImpl implements UserService{
    
	private UserDao ud;
	
	public UserDao getUd() {
		return ud;
	}

	public void setUd(UserDao ud) {
		this.ud = ud;
	}

	@Override
	public void addUser(UserVo user) throws BlogException, Exception {
		if(1==isBlogName(user.getBlogName())){
			throw new BlogException("此用户已存在");
		}
		ud.addUser(user);
	}

	@Override
	public UserVo getUser(UserVo user) {
		return ud.getUser(user);
	}

	@Override
	public int isBlogName(String blogName) {
       return ud.isBlogName(blogName);
	}

	@Override
	public void changeBase(UserVo user) throws Exception{
	 
			ud.changeBase(user);		
	}

	@Override
	public void changePassword(UserVo user) {
		 ud.changePassword(user);
	}

	@Override
	public UserVo getUsesr(int buid) {
		return ud.getUsesr(buid);
	}

	@Override
	public List<UserVo> getList(UserVo uv) {
		return ud.getList(uv);
	}

	@Override
	public List<FriendVo> getFriendList(UserVo uv) {
		return ud.getFriendList(uv);
	}

	@Override
	public List<UserVo> getFriendsList(UserVo uv) {
		
		List<FriendVo> fvList=getFriendList(uv);
		List<UserVo>uvList=new ArrayList<UserVo>();
	
		//通过遍历从朋友表得到id得到真实的用户
		for (FriendVo fv : fvList) {
			uvList.add(ud.getUsesr(fv.getFrinendid()));
		}
		return uvList;
	}

	@Override
	public void addFriend(Integer buid, Integer rid) {
		ud.addFriend(buid, rid);
	}

	

}
